class Solution {
public:
    vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
        int n = arr.size();
        sort(arr.begin(), arr.end());
        vector<vector<int>> ret;
        int minAbs = INT_MAX;
        for (int i = 0; i < n - 1; i++)
        {
            if (arr[i + 1] - arr[i] < minAbs)
            {
                minAbs = arr[i + 1] - arr[i];
                ret.clear();
                ret.push_back({ arr[i], arr[i + 1] });
            }
            else if (arr[i + 1] - arr[i] == minAbs)
            {
                ret.push_back({ arr[i], arr[i + 1] });
            }
        }
        return ret;
    }
};

class Solution {
public:
    int longestSubstring(string s, int k) {
        int n = s.size();
        int ret = 0;
        for (int kinds = 1; kinds <= 26; kinds++)
        {
            int hash[128] = { 0 };
            for (int left = 0, right = 0, cnt = 0, val = 0; right < n; right++)
            {
                if (++hash[s[right]] == 1) cnt++;
                if (hash[s[right]] == k) val++;
                while (cnt > kinds)
                {
                    if (hash[s[left]] == 1) cnt--;
                    if (hash[s[left]] == k) val--;
                    hash[s[left]]--;
                    left++;
                }
                if (cnt == kinds && val == cnt)
                {
                    ret = max(ret, right - left + 1);
                }
            }
        }
        return ret;
    }
};

class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> st;
        int i = 0, n = popped.size();
        for (auto& x : pushed)
        {
            st.push(x);
            while (!st.empty() && st.top() == popped[i])
            {
                st.pop();
                i++;
            }
        }
        return i == n;
    }
};